<?

require(dirname(__FILE__).'/_base/BaseTaskProjectUser.php');

class TaskProjectUser extends BaseTaskProjectUser{
    
    public static function model($className=__CLASS__) {
        return parent::model($className);
    }
    
    public function relations() {
        return array(
            'user' => array(self::BELONGS_TO, 'TaskUser', 'user_id'),
            'project' => array(self::BELONGS_TO, 'TaskProject', 'project_id')
        );
    }
    
    public function UserInProject($userID, $projectID){
        $userID = intval($userID);
        $projectID = intval($projectID);
        
        if($userID < 0) throw new CException(TaskModule::t('messages', 'Не указан пользователь.'));
        if($projectID < 0) throw new CException(TaskModule::t('messages', 'Не указан проект.'));
        
        $count = self::model()->countByAttributes(array(
            'user_id' => $userID,
            'project_id' => $projectID
        ));
        
        return $count > 0;
    }
    
}
